//package com.zhinong.config;
//
//
//import org.springframework.ai.chat.client.ChatClient;
//import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
//import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
//import org.springframework.ai.chat.memory.ChatMemory;
//import org.springframework.ai.chat.memory.InMemoryChatMemory;
//import org.springframework.ai.ollama.OllamaChatModel;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
//@Configuration
//public class CommonConfiguration {
//    @Bean
//    public ChatMemory chatMemory() {
//        return new InMemoryChatMemory();
//    }
//
//    @Bean
//    public ChatClient chatClient(OllamaChatModel model) {
//        return ChatClient.builder(model)
//                .defaultSystem("你是一个农业智能助手，可以为我解答各种农业相关问题，包括种植技术、病虫害防治、农产品市场信息等。")
//                .defaultAdvisors(
//                        new SimpleLoggerAdvisor(),
//                        new MessageChatMemoryAdvisor(chatMemory()))
//                .build();
//    }
//}


package com.zhinong.config;


        import org.springframework.ai.chat.client.ChatClient;
        import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
        import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
        import org.springframework.ai.chat.memory.ChatMemory;
        import org.springframework.ai.chat.memory.InMemoryChatMemory;
        import org.springframework.context.annotation.Bean;
        import org.springframework.context.annotation.Configuration;

@Configuration
public class CommonConfiguration {
    @Bean
    public ChatMemory chatMemory() {
        return new InMemoryChatMemory();
    }

    @Bean
    public ChatClient chatClient(ChatClient.Builder builder) {
        return builder
                .defaultSystem("你是一个农业智能助手，可以为我解答各种农业相关问题，包括种植技术、病虫害防治、农产品市场信息等。")
                .build();
    }
}
